package day_2022_7_to_8.day48;

/**
 * @author haomin
 * @date 2022/08/31 15:48
 **/
public class Day46_4_Offer26_IsSubStructure {
    class Solution {
        public boolean isSubStructure(TreeNode A, TreeNode B) {
            if(A == null || B ==null) return false;
            return dfs(A, B) || isSubStructure(A.left, B) || isSubStructure(A.right, B);
        }
        private boolean dfs(TreeNode A, TreeNode B){
            if(B == null) return true;
            if(A == null) return false;
            return A.val == B.val && dfs(A.left, B.left) && dfs(A.right, B.right);
        }
    }
}